package week0501;


import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

public class Main5 {

    private static Scanner in;

    public static void main(String[] args) {
        in = new Scanner(System.in);
        int n;
        while (true) {
            n = in.nextInt();
            List<PersonSortable> personSortables = new ArrayList<>();
            for (int i = 0; i < n; i++) {
                personSortables.add(new PersonSortable(in.next(), in.nextInt()));
            }
            Collections.sort(personSortables, new Comparator<PersonSortable>() {
				@Override
				public int compare(PersonSortable o1, PersonSortable o2){
	            	return o1.getName().compareTo(o2.getName());
	            }            	
			});
            System.out.println("NameComparator:sort");
            for (PersonSortable personSortable : personSortables) {
                System.out.println(personSortable.toString());
            }
            Collections.sort(personSortables, (PersonSortable o1, PersonSortable o2)->{
            	 if (o1.getAge() >= o2.getAge()) {
                     return 1;
                 }
                 else {
                     return -1;
                 }
            });
            System.out.println("AgeComparator:sort");
            for (PersonSortable personSortable : personSortables) {
                System.out.println(personSortable.toString());
            }
            System.out.println("201621123016-郑玉波");
        }

    }

}

class PersonSortable {

    private String name;
    private int age;

    public PersonSortable(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return name + "-" + age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

}
